package me.zhengjie.modules.other.rest;


import com.qiaofang.applet.service.other.domain.EmployeeLabel;
import com.qiaofang.applet.service.other.service.EmployeeLabelService;
import com.qiaofang.applet.service.other.service.dto.EmployeeLabelUuidDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 标签：经纪人标签管理
 *
 * @author oyl
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "标签：经纪人标签管理")
@RequestMapping("/api/employeeLabel")
public class EmployeeLabelController {

    @Autowired
    private EmployeeLabelService employeeLabelService;

    @GetMapping
    @ApiOperation(value = "查询经纪人标签列表", notes = "查询经纪人标签列表")
    public ResponseEntity<Page<EmployeeLabel>> searchEmployeeLabel(){
        List<EmployeeLabel> employeeLabels = employeeLabelService.findAllEmployeeLabel(SecurityUtils.getCorporationCode());
        return ResponseEntity.ok(new PageImpl<>(employeeLabels));
    }

    @PostMapping
    @ApiOperation(value = "新增经纪人标签", notes = "新增经纪人标签")
    public ResponseEntity<Object> insertEmployeeLabel(@Validated @RequestBody EmployeeLabel employeeLabel){
        employeeLabelService.saveEmployeeLabel(employeeLabel, SecurityUtils.getCorporationCode());
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PutMapping
    @ApiOperation(value = "修改经纪人标签", notes = "修改经纪人标签")
    public ResponseEntity<Object> updateEmployeeLabel(@Validated @RequestBody EmployeeLabel employeeLabel){
        employeeLabelService.saveEmployeeLabel(employeeLabel, SecurityUtils.getCorporationCode());
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @DeleteMapping
    @ApiOperation(value = "删除经纪人标签", notes = "删除经纪人标签")
    public ResponseEntity<Object> removeEmployeeLabel(@RequestBody List<EmployeeLabelUuidDto> employeeLabelUuidDto){
        employeeLabelService.removeEmployeeLabel(employeeLabelUuidDto.get(0).getLabelUuid(),SecurityUtils.getCorporationCode());
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
